import java.awt.*;
import java.awt.event.*;

import javax.media.opengl.*;
import javax.media.opengl.glu.*;
import javax.swing.JFrame;

import com.sun.opengl.util.*;

import java.nio.FloatBuffer;
import java.nio.IntBuffer;

public class Cube extends Shape {
	
	public Cube(float s){
		centerX = 0;
		centerY = 0;
		centerZ = 0;
		scale = s;
		rotateNow = false;
		
		indi = new int[24];
		indi[0] = 4;
		indi[1] = 5;
		indi[2] = 1;
		indi[3] = 0;
		indi[4] = 3;
		indi[5] = 2;
		indi[6] = 6;
		indi[7] = 7;
		indi[8] = 0;
		indi[9] = 1;
		indi[10] = 2;
		indi[11] = 3;
		indi[12] = 7;
		indi[13] = 6;
		indi[14] = 5;
		indi[15] = 4;	
		indi[16] = 1;
		indi[17] = 5;
		indi[18] = 6;
		indi[19] = 2;
		indi[20] = 4;
		indi[21] = 0;
		indi[22] = 3;
		indi[23] = 7;
		
	}
	
	public void draw(GL gl){
		float[] v = {
				0.5f,0.5f,0.5f,   // 0
				-0.5f,0.5f,0.5f,  // 1
				-0.5f,-0.5f,0.5f, // 2
				0.5f,-0.5f,0.5f,  // 3
				0.5f,0.5f,-0.5f,  // 4
				-0.5f,0.5f,-0.5f, // 5
				-0.5f,-0.5f,-0.5f,// 6
				0.5f,-0.5f,-0.5f }; //7
		float[] n = {
				0.5f,0.5f,0.5f,   // 0
				-0.5f,0.5f,0.5f,  // 1
				-0.5f,-0.5f,0.5f, // 2
				0.5f,-0.5f,0.5f,  // 3
				0.5f,0.5f,-0.5f,  // 4
				-0.5f,0.5f,-0.5f, // 5
				-0.5f,-0.5f,-0.5f,// 6
				0.5f,-0.5f,-0.5f }; //7
		
		normal = n;
		vert = performTransform(v, true);
		
		vBuf = BufferUtil.newFloatBuffer(vert.length);
		vBuf.put(vert);
		vBuf.rewind();
		nBuf = BufferUtil.newFloatBuffer(normal.length);
		nBuf.put(normal);
		nBuf.rewind();
		iBuf = BufferUtil.newIntBuffer(indi.length);
		iBuf.put(indi);
		iBuf.rewind();
		
		gl.glMatrixMode(GL.GL_MODELVIEW);
		gl.glPushMatrix();

		gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
		gl.glEnableClientState(GL.GL_NORMAL_ARRAY);

		gl.glVertexPointer(3, GL.GL_FLOAT, 0, vBuf);
		gl.glNormalPointer(GL.GL_FLOAT, 0, nBuf);
		gl.glColor3f(1.0f, color, 0.0f); // Red
		gl.glDrawElements(GL.GL_QUADS, indi.length, GL.GL_UNSIGNED_INT, iBuf);
		gl.glPopMatrix();
		
		gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
		gl.glDisableClientState(GL.GL_NORMAL_ARRAY);
		gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY);

	}	
}
